package com.ice.dockerredis.app;

import java.util.Date;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;

/**
 * @author icewinters
 */
public class SendEmail {


    public static void main(String[] args) throws MessagingException {

        Properties pro = new Properties();

        // 邮件发送协议
        pro.setProperty("mail.transport.protocol","smtp");
        // SMTP 邮件服务器
        pro.setProperty("mail.host","smtp.126.com");
        // 是否要求身份认证
        pro.setProperty("mail.smtp.auth","true");
        // 开启 debug 调试
        pro.setProperty("mail.debug","true");


        Session session = Session.getInstance(pro);
        session.setDebug(true);
        Message msg = new MimeMessage(session);

        msg.setFrom(new InternetAddress("icewinters@126.com"));

        msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse("1536437288@qq.com"));
//        msg.setRecipients(Message.RecipientType.CC, InternetAddress.parse("1172456219@qq.com"));

        msg.setSubject("不装了，摊牌了");


        String mailBody = "this is a test <br> 我的宝儿";

        BodyPart bp = new MimeBodyPart();
        bp.setContent("<meta http-equiv=Content-Type content=text/html; charset=UTF-8>" + mailBody,
                "text/html;charset=UTF-8");
        // 在组件上添加邮件文本
        MimeMultipart mp = new MimeMultipart();
        mp.addBodyPart(bp);

        msg.setContent(mp);

        msg.setSentDate(new Date());

        Transport smtp = session.getTransport("smtp");

        smtp.connect("smtp.126.com",25,"icewinters@126.com","JPJVCXALOLRUYCIU");

        // 把邮件发送出去
        smtp.sendMessage(msg, msg.getAllRecipients());
        smtp.close();

    }

}
